<?php
require_once '../../bbs/include/common.inc.php';
require_once '../../classes/include.php';

if(!empty($_POST['add'])){

	$title		= $_POST["title"];
	$datetime	= $_POST["datetime"];
	$topiccode	= $_POST["topiccode"];
	
	$content	= htmlspecialchars( stripslashes( $_POST['editor1'] ) );
	
	$content	= str_replace("'", "''", $content);
	$datetime	= str_replace("'", "''", $datetime);

	$sql = "insert into article (title, content, inputtime, topiccode ) values('".$title."', '".$content."', '".time()."', '".$topiccode."')";
	$query = $db->query($sql);
	
	echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />";
	echo "<script>";
	echo "alert('文章增加成功!');";
	echo "location.href='list.php';";
	echo "</script>";
	exit;
}
?>

<html><head>
<title></title>
<meta name="robots" content="noindex, nofollow" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="../ckeditor.js"></script>
<link rel="stylesheet" href="../../bbs/images/admincp/admincp.css" type="text/css" media="all" /> 
<script type="text/javascript">
<!--
function ChangeLanguage( languageCode )
{
	window.location.href = window.location.pathname + "?" + languageCode ;
}

function Check(frm)
{
	if(frm.title.value == ""){
		alert("请填写文章标题!");
		frm.title.focus();
		return false;
	}
	/*if(frm.datetime.value == ""){
		alert("请填写新闻日期!");
		frm.datetime.focus();
		return false;
	}
	if(!/^[0-9a-zA-Z_\u4E00-\u9FA5]*$/.test(frm.title.value)){
		alert("请正确填写文章标题,只能由中文、数字、字母和下划线组成!");
		frm.title.focus();
		return false;	
	}*/
	return true;
}
//-->
</script>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<form action="add.php" method="post" onsubmit="return Check(this)">
  <table cellspacing=1 cellpadding=3 width="100%" align=center bgcolor="#CBDFF3" border=0>
    <tr class="tableheader"> 
      <td colspan="2">&nbsp;&nbsp;增加文章</td>
    </tr>
    <tr class="tablecontent"> 
      <td width="100" align="left">&nbsp;&nbsp;文章标题:</td>
      <td>
        <input type="text" name="title" maxlength="255" class="FormText" size="100">
      </td>
    </tr>
    <tr class="tablecontent"> 
      <td width="100" align="left">&nbsp;&nbsp;所属栏目:</td>
      <td>
        <select name="topiccode">
        	<?php
        	for($x = 0; $x < count($topicArr); $x++){
        		if($topicArr[$x][3] != ""){
        			$id = $topicArr[$x][0];
        			$level = $topicArr[$x][2];
        			$showName = $topicArr[$x][3];
        			if($level == 1){
        				echo "<option value=\"".$id."\">".$showName."</option>";
        			}
        			if($level == 2){
        				echo "<option value=\"".$id."\">&nbsp;&nbsp;".$showName."</option>";
        			}
        			if($level == 3){
        				echo "<option value=\"".$id."\">&nbsp;&nbsp;&nbsp;&nbsp;".$showName."</option>";
        			}
        		}
        	}
        	?>
        </select>
      </td>
    </tr>
    <!-- <tr class="tablecontent"> 
      <td width="100" align="left">&nbsp;&nbsp;新闻日期:</td>
      <td>
        <input type="text" name="datetime" maxlength="50" class="FormText" size="100">
      </td>
    </tr> -->
    <tr class="tablecontent"> 
      <td colspan="2" align="left">&nbsp;&nbsp;文章正文:</td>
    </tr>
    
    <tr class="tablecontent"> 
      <td colspan="2" align="center">
				<textarea class="ckeditor" cols="80" id="editor1" name="editor1" rows="10"></textarea>
      </td>
    </tr>
  </table>
  <BR>
  <table cellspacing=1 cellpadding=3 width="95%" align=center bgcolor="#FFFFFF" border=0>
    <tr> 
      <td colspan="2" align="center"> 
        <input type="submit" id="add_button" name="add" value="增加">
        <input type="button" value="返回" onclick="javascript:location.href='./list.php';">
      </td>
    </tr>
  </table>
</form>
</body>
</html>